
#ifndef _GOOGLEBUZZMENUFORM_H_
#define _GOOGLEBUZZMENUFORM_H_

#include <FBase.h>
#include <FUi.h>
#include <FGraphics.h>
#include <FMedia.h>
#include <FApp.h>
#include <FNet.h>

#include "GoogleBuzzTokenForm.h"
#include "GoogleBuzzNewActivity.h"
#include "../../Utility/MyUtil.h"

using namespace Osp::Base;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;
using namespace Osp::Graphics;
using namespace Osp::Media;
using namespace Osp::App;
using namespace Osp::Net::Http;


class GoogleBuzzMenuForm :
	public Osp::Ui::Controls::Form,
	public Osp::Ui::IActionEventListener,
	public Osp::Net::Http::IHttpTransactionEventListener
{

// Construction
public:
	GoogleBuzzMenuForm(void);
	virtual ~GoogleBuzzMenuForm(void);
	bool Initialize();
	result OnInitializing(void);
	result OnTerminating(void);

	static int FormId;

	void SetFormId(int FormId) {
		this->FormId = FormId;
	}
	static int GetFormId() {
		return FormId;
	}

	void Begin(void);

private:
	Button *pAddActivityButton;
	Button *pListActivityButton;
	GoogleBuzzTokenForm *pGoogleBuzzTokenForm;
	GoogleBuzzNewActivity *pGoogleBuzzNewActivity;

	String accessToken;
	String refreshToken;
	String apiKey;
	//String

protected:
	const static int ID_LIST_ACTIVITY = 1;
	const static int ID_ADD_ACTIVITY = 2;
	int status;
// Implementation
protected:

// Generated call-back functions
	virtual void  OnActionPerformed (const Osp::Ui::Control &source, int actionId);
	void OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs);
	void Download(String url, ByteBuffer *pBody, HttpHeader *pHeader, NetHttpMethod method);

	virtual void  OnLoadingErrorOccurred (LoadingErrorType error, const Osp::Base::String &reason);
	virtual void  OnTransactionReadyToRead (HttpSession &httpSession, HttpTransaction &httpTransaction, int availableBodyLen);

	virtual void  OnAnimationStopped (const Osp::Ui::Control &source){}
	virtual void  OnEstimatedProgress (int progress){}
	virtual void  OnHttpAuthenticationCanceled (void){}
	virtual bool  OnHttpAuthenticationRequestedN (const Osp::Base::String &host, const Osp::Base::String &realm,
				const Osp::Web::Controls::AuthenticationChallenge &authentication){ return false;}
	virtual void  OnLoadingCanceled (void){}
	virtual void  OnLoadingCompleted (void){}
	virtual bool  OnLoadingRequested (const Osp::Base::String &url, WebNavigationType type){ return false;}
	virtual void  OnLoadingStarted (void){}
	virtual DecisionPolicy OnWebDataReceived (const Osp::Base::String &mime,
			const Osp::Net::Http::HttpHeader &httpHeader){
		return WEB_DECISION_CONTINUE;
	}
	virtual void  OnTransactionAborted (HttpSession &httpSession, HttpTransaction &httpTransaction, result r){}
	virtual void  OnTransactionCertVerificationRequiredN (HttpSession &httpSession, HttpTransaction &httpTransaction, Osp::Base::String *pCert){}
	virtual void  OnTransactionCompleted (HttpSession &httpSession, HttpTransaction &httpTransaction){}
	virtual void  OnTransactionHeaderCompleted (HttpSession &httpSession, HttpTransaction &httpTransaction, int headerLen, bool bAuthRequired){}

	virtual void  OnTransactionReadyToWrite (HttpSession &httpSession, HttpTransaction &httpTransaction, int recommendedChunkSize){}

	void ReturnWebForm(void);
	void ContinueAfterGetTokenN(IList *pListArgs);
	void ProcessAddActivity(void);
	void ProcessShowListActivity(void);
	void AddActivityN(IList *pListArgs);
	void AddActivityCancel();
	void ShowListActivity(HttpSession &httpSession, HttpTransaction &httpTransaction);
public:
	const static RequestId REQUEST_GET_TOKEN_CANCEL = 1;
	const static RequestId REQUEST_GET_TOKEN_OK = 2;
	const static RequestId REQUEST_ADD_ACTIVITY_OK = 3;
	const static RequestId REQUEST_ADD_ACTIVITY_CANCEL = 4;
};

#endif
